import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 *
 * @ProjectName leetcode
 * @Author Ding
 * @CreateTime 2022/8/28 10:35 星期日
 */
public class Main {
    public static void main(String[] args) {
        int[] nums = new int[]{4,5,2,1};
        int[] queries = new int[]{3,10,21};
        System.err.println(Arrays.toString(answerQueries(nums,queries)));
    }

    public static int[] answerQueries(int[] nums, int[] queries) {
        int[] answer = new int[queries.length];
        for (int query : queries) {
            int min = nums[0];
            int sumMin = 0;
            for (int num : nums) {
                if (min > num){
                    min = num;
                }else{
                    sumMin = (min+sumMin) <= query ? min+sumMin : sumMin;
                }
            }
        }
        return answer;
    }
}
